计数器Counter类与重载运算符+ | 您所在的位置:网站首页 › java 符号重载 › 计数器Counter类与重载运算符+ |
typedef unsigned short USHORT; #include using namespace std; class Counter { public: Counter(); Counter(USHORT initialValue); ~Counter(){} USHORT getValue()const { return value; } void setValue(USHORT x) { value = x; } Counter operator+(const Counter&); private: USHORT value; }; Counter::Counter(USHORT initialValue): value(initialValue) { } Counter::Counter() : value(0) { } Counter Counter::operator+(const Counter& rhs) { return Counter(value + rhs.getValue()); } int main() { Counter varOne(2), varTwo(4), varThree; varThree = varOne + varTwo; cout |
CopyRight 2018-2019 实验室设备网 版权所有 |